/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fileman;


import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import java.io.File;


/**
 *
 * @author Murhaf
 */
public class ViewCreator {


  
    public static ListModel getFolders(){

        DefaultListModel listModel = new DefaultListModel();
        ArrayList folders = getFoldersAsList();
        Iterator itr = folders.iterator();
        while(itr.hasNext()){
        listModel.addElement(itr.next());
        }

        return listModel;


    }

    public static ListModel getFiles(Object path){
        DefaultListModel listModel = new DefaultListModel();
        if(path == null)
            return listModel;


        
        ArrayList files = getFilesAsList(path.toString());
        Iterator itr = files.iterator();
        while(itr.hasNext()){
        listModel.addElement(itr.next());
        }

        return listModel;


    }

    public static ArrayList getFoldersAsList() {

        ArrayList folders = new ArrayList();
        String path = "c:/Nodes/";

        String files;
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();


        for (int i = 0; i < listOfFiles.length; i++) {
            folders.add(listOfFiles[i].getName());

//            if (listOfFiles[i].isFile()) {
//                files = listOfFiles[i].getName();
//
//            }


        }
        return folders;
    }


    public static ArrayList getFilesAsList(String path) {

        ArrayList files = new ArrayList();

            path = "c:/Nodes/"+path+"/";
       

       
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();


        for (int i = 0; i < listOfFiles.length; i++) {
            
            if (listOfFiles[i].isFile()) {
                files.add(listOfFiles[i].getName());
            //    files = listOfFiles[i].getName();

            }


        }
        return files;
    }

}
